package com.app.designpatternslearn.creational.singletonpattern.code

class SingleObject private constructor() {

    companion object {
        val instance: SingleObject by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            SingleObject()
        }
    }

    fun doSomething() {
        println("SingleObject --> doSomething")
    }
}

class SingleObject2 private constructor() {

    companion object {
        private var instance: SingleObject2? = null
            get() {
                if (field == null) {
                    field = SingleObject2()
                }
                return field
            }
        @Synchronized
        fun getIns(): SingleObject2{
            return instance!!
        }
    }

    fun doSomething() {
        println("SingleObject2 --> doSomething")
    }

}